<template>
  <view class=".goods-box">
    <view class="goods-item">
      <view class="goods-item-left">
        <radio color="#E16531" :checked="goods.goods_state" v-if="isCart" @click="onClickEvent"></radio>
        <image class="goods_img" :src="goods.goods_small_logo||defaultPic" show-menu-by-longpress="true"></image>
      </view>
      <view class="goods-item-right">
        <view class="goods-title">
          {{goods.goods_name}}
        </view>
        <view class="goods-box-right-bottom">
          <view class="goods-price">
            ￥{{goods.goods_price | toFixed}}
          </view>
          <view class="number-box" v-if="isCart">
            <uni-number-box v-model="goods.goods_count" :min="1" :max="99" @change="numChange"></uni-number-box>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      goods:{
        type:Object,
        default:{}
      },
      isCart:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        defaultPic:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
      };
    },
    methods:{
      onClickEvent(){
        this.$emit('radio-change',{
          goods_id:this.goods.goods_id,
          goods_state:!this.goods.goods_state
        })
      },
      numChange(val){
        this.$emit('num-change',{
          goods_id:this.goods.goods_id,
          goods_count:+val
        })
      }
    },
    filters:{
      toFixed(num){
        return num.toFixed(2)
      }
    }
  }
</script>

<style lang="scss">
.goods-item{
  display: flex;
  padding: 6px 0;
  margin: 0 10px;
  border-bottom: 1px solid #eee;
  .goods-item-left{
    display: flex;
    align-items: center;
    justify-content: space-between;
    .goods_img{
      width: 100px;
      height: 100px;
      display: block;
    }
  }
  .goods-item-right{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    padding: 0 10px 6px 10px;
    .goods-title{
      font-size: 13px;
    }
    .goods-box-right-bottom{
      display: flex;
      justify-content: space-between;
      align-items: center;
      .goods-price{
        color: #E16531;
        font-weight: bold;
        font-size: 16px;
        transform: scaleY(1.1);
      }
    }
  }
}
</style>
